﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

using AttributeRouting;
using AttributeRouting.Web.Mvc;
using PH.Model.Schools;
using PH.Logic.Schools;
using Newtonsoft.Json.Linq;
using PH.Model.Results;
namespace PH.Web.Management.Areas.School.Controllers
{
    [RouteArea("School")]
    [RoutePrefix("Config")]
    public class ConfigApiController : ApiController
    {
        [Route("GetGrades")]
        [HttpPost]
        public JsonEntitySet<GradeModel> GetGrades(JObject request)
        {
            string errinfo = "no data";
            try
            {
                var schType = request.Value<int>("schType");
                var result = GradeLogic.GetGrades(schType);
                return new JsonEntitySet<GradeModel>(result);
            }
            catch (Exception ex)
            {
                errinfo = ex.Message;
                Common.Logger.Error("", ex);
            }
            return new JsonEntitySet<GradeModel>(null, errinfo, false);
        }
        [Route("GetALLGrades")]
        [HttpPost]
        public JsonEntitySet<GradeModel> GetALLGrades(JObject request)
        {
            string errinfo = "no data";
            try
            {
                var result = GradeLogic.GetGrades();
                return new JsonEntitySet<GradeModel>(result);
            }
            catch (Exception ex)
            {
                errinfo = ex.Message;
                Common.Logger.Error("", ex);
            }
            return new JsonEntitySet<GradeModel>(null, errinfo, false);
        }

        [Route("GetSchoolTypes")]
        [HttpPost]
        public JsonEntitySet<SchoolTypeModel> GetSchoolTypes()
        {
            string errinfo = "no data";
            try
            {
                var result = SchoolTypeLogic.GetAll();
                return new JsonEntitySet<SchoolTypeModel>(result);
            }
            catch (Exception ex)
            {
                errinfo = ex.Message;
                Common.Logger.Error("", ex);
            }
            return new JsonEntitySet<SchoolTypeModel>(null, errinfo, false);
        }
    }
}
